package com.yc.spring.jdbc.dao;

import com.yc.spring.jdbc.bean.Record;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Company 源辰信息
 *
 * @author navy
 * @date 2024/8/4
 * Email haijunzhou@hnit.edu.cn
 */
@Repository
public class OprecordDao {

    @Autowired
    JdbcTemplate jdbcTemplate;

    public void insert(Record record){
        jdbcTemplate.update("insert into bank_oprecord values(" +
                "default,?,?,?,now(),null)",
                record.getAid(), record.getMoney(), record.getCharge());
    }


    public List<Record> selectByAid(int aid){
        // TODO 这里要自定义映射, 因为数据字段与实体类属性名不相同
        return jdbcTemplate.query("select * from bank_account where aid=?",
                new BeanPropertyRowMapper<Record>(Record.class),
                aid);
    }

}
